package com.ledou44.ledourpc.clienthandler;

import com.alibaba.fastjson.JSON;
import com.ledou44.ledourpc.dto.LedouSradDTO;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author ledou44
 * 用于进行服务注册的handler，这个handler其实应该属于servicehandler包下面
 */
public class RegisterClientHandler extends ChannelHandlerAdapter{

    /**
     * 需要发送给客户端的消息
     */
    private final LedouSradDTO message;

    public RegisterClientHandler(LedouSradDTO message) {
        this.message = message;
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.writeAndFlush(JSON.toJSONString(message));
        super.channelActive(ctx);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//        message.setSuccess(true);
//        message.setResult(msg);
//        ctx.close();
        super.channelRead(ctx, msg);
    }

}
